$(function() {
    var _url = '{{ $url }}';
    var _app_url = '{{ $app_url }}';
    var _invitation_code = '{{ $invitation_code }}';
    if (_invitation_code.length =='') {
        _invitation_code ==1234;
    }
    $('#invitation_code').val(_invitation_code);
console.log(_invitation_code);
	$("#button").click(function() {
        var name = $("#userName").val();
		var password = $("#userPass").val();
		var nickname = $("#nickName").val();
		var invitation_code = $("#Invitation_Code").val();
		if(name.length < 4 || name.length > 15 || name == "") {
				$("#tip").html("用户名必须为4-15位字符，请重新输入！")
				setTimeout(function(){$("#tip").html("")}, 2000);
		} else {
			 if(password.length < 6 || password == "") {
				$("#tip").html("密码必须大于6位字符，请重新输入！")
				setTimeout(function(){$("#tip").html("")}, 2000);
			} else if(nickname == "") {
				$("#tip").html("请输入昵称！")
				setTimeout(function(){$("#tip").html("")}, 2000);
			}else {
			 	var _ajax_url = _url+'/api/v1/register';
				$.ajax({
					url: _ajax_url,
					data: {
						name: name,
						password: password,
						nickname: nickname,
                        invitation_code: invitation_code
					},
					async: true,
					type: "POST",
					success: function(result) {
						console.log(result);
                        // if (result.code == 0) {
                        //     window.location.href= _app_url+'/api/v1/users/down';
                        // }
					}
				});
			}
		}
	})
});